About AppleScript and Outlook Express 5.0

AppleScript is a scripting language for automating tasks on Apple Macintosh computers. It is useful in cases where you need to repeatedly perform a procedure that has many steps. It is also useful when you need to use two or more Macintosh application programs together to accomplish your work.

This document is written for use with AppleScript, but also applies to scripting Outlook Express with Frontier, Perl, and QuicKeys, or to scripting it by directly sending AppleEvents. It is meant to supplement the Microsoft Outlook Express 5.0 AppleScript Reference.

Documentation

General AppleScript Documentation

This document assumes you're already familiar with AppleScript and know how to use the Macintosh Script Editor to browse scripting dictionaries and to create and debug scripts. If you haven't used AppleScript before, you should study at least one of the following:

AppleScript Documentation for Outlook Express

To learn about the scripting classes and commands provided by Outlook Express, read the Microsoft Outlook Express 5.0 AppleScript Reference. This document contains essentially all of the information in the AppleScript dictionary of Outlook Express in an accessible format, including all its AppleScript words, as well as code examples and explanatory material for obscure commands. If the Reference conflicts with the dictionary, however, the dictionary should be treated as definitive.

You may also find information on scripting Outlook Express in one of the following Usenet newsgroups. Outlook Express users and scripters congregate here and can often answer tough questions:

Also essential for the Outlook Express scripter is the The Unofficial Outlook Express Page. You can join an Outlook Express mailing list at this site, where users of the application exchange information. Several Outlook Express developers are list regulars. You can reach the unofficial page from the official Microsoft Outlook Express for Macintosh page.


Scripting Outlook Express 5.0

Overview

Outlook Express 5.0 uses the Apple Object Model for its scripting interface. For its mail interface, it uses the Apple Mail Suite. Outlook Express 5.0 has scripting support for local messages, POP and IMAP accounts, Usenet news, and an address book.

In addition to the Required and Standard AppleScript suites, Microsoft Outlook Express provides several suites of its own: the Outlook Express Mail and News suite, the Outlook Express Contact suite, and the URL suite. Together these suites provide the scripting commands and classes you need to tell Outlook Express what tasks to perform.

You can see what commands, classes, and properties are implemented in Outlook Express by opening the AppleScript Script Editor application that came with your Macintosh, selecting Open Dictionary... from the File menu, and then choosing Outlook Express. The text that results is called the AppleScript dictionary for Outlook Express.

If you want more information on AppleScript commands than appears in the Outlook Express dictionary, you can read the Outlook Express AppleScript Reference, which goes into more detail.

Verbs

The number of verbs in the Outlook Express AppleScript dictionary has been minimized and as much as possible is done with the standard verbs, in keeping with Apple's guidelines.

The Script Menu

The Script menu is represented in the Outlook Express 5.0 menu bar by a script icon. Once you have written and debugged your own scripts, you can add them to the Outlook Express Script menu by saving them as compiled scripts and then dragging them into the Script Menu Items subfolder of the Outlook Express folder. The Script menu will be updated whenever items are added to the folder (although it won�t update if an item is simply renamed), and the items in the Script menu folder can be any sort of OSA script with an �osas� file type. This includes Frontier scripts and even QuicKeys scripts. Note that if you hold down the option key while opening a script on the Script menu, it will be opened in the Script Editor for editing.

You can also create subfolders within the Script Menu Items folder. The Script menu will display items in subfolders as hierarchical menus. There is a limit of 14 such menus, however, and if there are too many, an error dialog will be shown.

To launch a script that you have added to the Script menu, just choose the script from the menu. Keyboard equivalents for menu items can be defined by a forward slash ('/'), followed by modifiers. Modifiers can be 's' for shift, 'o' for option, 'm' for command, or 'c' for control. If no modifiers are specified, command is assumed. For example, �/cF� would be control+F, �/F� would be command+F, and �/msF� would be command+shift+F. Outlook Express does not check for conflicts, and the results of conflicts will be undefined.

After a script is run, it will be saved to disk if it needs to be. For example, if the script has a property that is modified by the script, it needs to be saved to update the property value. For example:

    property timesRun : 0
    set timesRun to timesRun + 1
    display dialog "I've been run " & timesRun & " times."

While running a script, Outlook Express 5.0 will let you switch to other applications and will respond to update events. It will also continue running threads. However, it will not respond to key pressing or keyboard commands (these might be used to open modal dialogs, which could cause problems).

Unicode Support

Apple introduced support for Unicode in AppleScript with Mac OS 8.5. Unicode is an Internet standard for displaying text in many alphabets besides the familiar Roman one, such as Cyrillic and Japanese Kanji. Unicode also makes displaying accented Roman characters much easier.

By default, all string and Unicode text properties are returned as regular text, but if you add the command "as unicode text", the Unicode version will be returned. You can also set a string property to Unicode text. Here is an example that shows how to use Unicode text:

     get the city of the business address of NewContact as unicode text

Scripting Tips and Tricks

Debugging Scripts

Be sure to keep both the Script Editor's result window and its event log window open at all times when creating and debugging a new script. They may display valuable information.

Getting the Class of Selected Items in Outlook Express

If you want to know the class of the selected object in the currently active Outlook Express window, set a variable to be equal to the selection and then get the class of that variable. Don't just get the class of the selection, because the class of selection itself is "property."

Using Variables and Parentheses

Break complicated expressions into parts and store each part in a variable. For example, you might break this command:

    set V to the W of the X of the Y of the Z

into:

    set V1 to the Y of the Z
    set V2 to the X of the V1
    set V to the W of the V2

This will make your script much easier to debug. Note that the second example may be somewhat slower, because it must send three AppleEvents to Outlook Express instead of only one.

Use parentheses wherever possible to make explicit any assumptions you have about the order of evaluation in expressions.

Script Template

The following is an AppleScript template that you can use to process messages selected by the user. Simply copy this template into the Script Editor, and then replace the comment line that reads "[Insert your code here]" with your own AppleScript code to process a message. When the user runs your script, your code will process all current messages.

See the entry for the current messages property in the Reference for information on what qualifies as a "current message." See the scripts in the "Color" folder of the Script menu for simple examples of this template in actual use.


-- figure out which messages to process
on run
    tell application "Outlook Express"
        set theMessages to the current messages
        repeat with theMsg in theMessages
            my ProcessMsg (theMsg)
        end repeat
    end tell
end run

-- process the messages
on ProcessMsg (theMsg)
    -- [Insert your code here]
end ProcessMsg